2020-2021 Sunseeker Telemetry and Lighting System
rtc_c_ex1_calendarmode.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
67 //******************************************************************************
68 
69 #include "driverlib.h"
70 
71 volatile Calendar newTime;
72 
73 void main (void)
74 {
75  Calendar currentTime;
76 
77  WDT_A_hold(WDT_A_BASE);
78 
79  //Set P1.0 to output direction
80  GPIO_setAsOutputPin(
81  GPIO_PORT_P1,
82  GPIO_PIN0
83  );
84 
85  //Initialize LFXT1
86  UCS_turnOnLFXT1(UCS_XT1_DRIVE_3,
87  UCS_XCAP_3
88  );
89 
90  //Setup Current Time for Calendar
91  currentTime.Seconds = 0x00;
92  currentTime.Minutes = 0x26;
93  currentTime.Hours = 0x13;
94  currentTime.DayOfWeek = 0x03;
95  currentTime.DayOfMonth = 0x20;
96  currentTime.Month = 0x07;
97  currentTime.Year = 0x2011;
98 
99  //Initialize Calendar Mode of RTC
100  /*
101  * Base Address of the RTC_C
102  * Pass in current time, intialized above
103  * Use BCD as Calendar Register Format
104  */
105  /*Refer device header file and pass in baseaddress parameter for RTC_C
106  as RTC_C_BASE or RTC_CE_BASE as defined in User's guide*/
107  RTC_C_initCalendar(RTC_C_BASE,
108  &currentTime,
109  RTC_C_FORMAT_BCD);
110 
111  //Setup Calendar Alarm for 5:00pm on the 5th day of the week.
112  //Note: Does not specify day of the week.
113  /*Refer device header file and pass in baseaddress parameter for RTC_C
114  as RTC_C_BASE or RTC_CE_BASE as defined in User's guide*/
115  RTC_C_configureCalendarAlarmParam param = {0};
116  param.minutesAlarm = 0x00;
117  param.hoursAlarm = 0x17;
118  param.dayOfWeekAlarm = RTC_C_ALARMCONDITION_OFF;
119  param.dayOfMonthAlarm = 0x05;
120  RTC_C_configureCalendarAlarm(RTC_C_BASE, &param);
121 
122  //Specify an interrupt to assert every minute
123  /*Refer device header file and pass in baseaddress parameter for RTC_C
124  as RTC_C_BASE or RTC_CE_BASE as defined in User's guide*/
125  RTC_C_setCalendarEvent(RTC_C_BASE,
126  RTC_C_CALENDAREVENT_MINUTECHANGE);
127 
128  //Enable interrupt for RTC Ready Status, which asserts when the RTC
129  //Calendar registers are ready to read.
130  //Also, enable interrupts for the Calendar alarm and Calendar event.
131  /*Refer device header file and pass in baseaddress parameter for RTC_C
132  as RTC_C_BASE or RTC_CE_BASE as defined in User's guide*/
133  RTC_C_enableInterrupt(RTC_C_BASE,
134  RTCRDYIE + RTCTEVIE + RTCAIE);
135  RTC_C_enableInterrupt(RTC_C_BASE,
136  RTCRDYIFG + RTCTEVIFG + RTCAIFG);
137 
138  //Start RTC Clock
139  /*Refer device header file and pass in baseaddress parameter for RTC_C
140  as RTC_C_BASE or RTC_CE_BASE as defined in User's guide*/
141  RTC_C_startClock(RTC_C_BASE);
142 
143  //Enter LPM3 mode with interrupts enabled
144  __bis_SR_register(LPM3_bits + GIE);
145  __no_operation();
146 }
147 
148 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
149 #pragma vector=RTC_VECTOR
150 __interrupt
151 #elif defined(__GNUC__)
152 __attribute__((interrupt(RTC_VECTOR)))
153 #endif
154 void RTC_ISR (void)
155 {
156  switch (__even_in_range(RTCIV, 16)) {
157  case RTCIV_NONE: break; //No interrupts
158  case RTCIV_RTCOFIFG: break; //RTCOFIFG
159  case RTCIV_RTCRDYIFG: //RTCRDYIFG
160  //Toggle P1.0 every second
161  GPIO_toggleOutputOnPin(
162  GPIO_PORT_P1,
163  GPIO_PIN0);
164  break;
165  case RTCIV_RTCTEVIFG: //RTCEVIFG
166  //Interrupts every minute
167  __no_operation();
168 
169  //Read out New Time a Minute Later BREAKPOINT HERE
170  /*Refer device header file and pass in baseaddress
171  parameter for RTC_C as RTC_C_BASE or RTC_CE_BASE as
172  defined in User's guide*/
173  newTime = RTC_C_getCalendarTime(RTC_C_BASE);
174  break;
175  case RTCIV_RTCAIFG: //RTCAIFG
176  //Interrupts 5:00pm on 5th day of week
177  __no_operation();
178  break;
179  case RTCIV_RT0PSIFG: break; //RT0PSIFG
180  case RTCIV_RT1PSIFG: break; //RT1PSIFG
181 
182  default: break;
183  }
184 }
185 
void main(void)
void RTC_ISR(void)
volatile Calendar newTime
MPU_initThreeSegmentsParam param
__no_operation()